package com.schoolET.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.schoolET.entity.Wechat;
import com.schoolET.entity.dto.WechatInfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 微信用户 Mapper 接口
 * </p>
 *
 * @author lin
 * @since 2024-06-04
 */
@Mapper
public interface WechatMapper extends BaseMapper<Wechat> {

    Page<WechatInfoDTO> selectByNicknameAndPosition(Page<?> page,
                                                    @Param("nickName")String nickName,
                                                    @Param("position")String position);

    @Select("SELECT t1.* FROM wechat t1 \n" +
            "LEFT JOIN wechat_and_region t2 ON t1.id=t2.wechat_id\n" +
            "LEFT JOIN region t3 ON t2.region_id = t3.id\n" +
            "WHERE t1.flag = 0 AND t3.flag =0\n" +
            "AND t1.open_id =#{openId} and t2.default_location = 1")
    WechatInfoDTO selectByOpenId(String openId);

    Integer updateWechatInfo(@Param("openId") String openId,
                             @Param("nickName") String nickName,
                             @Param("phone") String phone);
}
